package org.simplecrm.repository.event.eventtype;

import org.simplecrm.domain.event.eventtype.EventType;
import org.slf4j.Logger;
import org.springframework.stereotype.Repository;

import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;
import java.util.LinkedList;
import java.util.List;

/**
 * Created by Oleksandr_Terekh on 9/4/2014.
 */
@Repository("eventTypeDAO")
public class EventTypeJdbcDAO implements EventTypeDAO {

    @org.simplecrm.misc.loginject.Logger
    private Logger LOGGER;

    @PersistenceContext(unitName = "entityManager")
    private EntityManager entityManager;

    @Override
    public List<EventType> getAllEventTypes() {

        List<EventType> eventTypeList;

        Query query = entityManager.createNamedQuery("EventType.findAll");
        eventTypeList = query.getResultList();
        if (eventTypeList == null) {
            eventTypeList = new LinkedList<>();
        }

        return eventTypeList;
    }
}
